﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace week2.classes
{
    class Account
    {
        protected string Username { get; }//用户名，不可更改
        private string Password { get; set; }//密码，可改
        protected int Balance { get; set; }//余额
        public Account(string name,string password)
        {
            Username = name;
            Password = password;
            Balance = 0;
        }
        public delegate void BigMoneyOut(BigMoney args);
        public event BigMoneyOut BigMoneyFetched;

        protected void SendEvent(BigMoney BigM)
        {
            if (BigMoneyFetched != null)
            {
                BigMoneyFetched(BigM);
            }
        }
        public bool Login(string pwd)//暂时只考虑一个账户
        {
            if (pwd == Password) return true;
            return false;
        }

        public bool SaveM(int money)//存钱
        {
            BadMoney bm = new BadMoney();
            if (bm.IsBM())
            {
                throw new BadMoneyException();
            }
            Balance += money;
            return true;
        }

        public bool WithDraw(int money)//取出
        {
            if (money > Balance) return false;
            if(money > 10000)
            {
                BigMoney bm = new BigMoney();
                bm.money = money;
                bm.UserName = Username;
                SendEvent(bm);
            }
            Balance -= money;
            return true;
        }

        public int GetBalance()
        {
            return Balance;
        }

    }
}
